package com.ruoyi.SSL.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.SSL.domain.SslCloudKey;
import com.ruoyi.SSL.service.ISslCloudKeyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 云厂商key管理Controller
 *
 * @author ruoyi
 * @date 2024-12-12
 */
@Controller
@RequestMapping("/SSL/cloudKeySecret")
public class SslCloudKeyController extends BaseController
{
    private String prefix = "SSL/cloudKeySecret";

    @Autowired
    private ISslCloudKeyService sslCloudKeyService;

    @RequiresPermissions("SSL:cloudKeySecret:view")
    @GetMapping()
    public String cloudKeySecret()
    {
        return prefix + "/cloudKeySecret";
    }

    /**
     * 查询云厂商key管理列表
     */
    @RequiresPermissions("SSL:cloudKeySecret:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SslCloudKey sslCloudKey)
    {
        startPage();
        List<SslCloudKey> list = sslCloudKeyService.selectSslCloudKeyList(sslCloudKey);
        return getDataTable(list);
    }

    @GetMapping("/selectKeyInfo")
    public String selectKeyInfo(String cloudVendor, ModelMap modelMap){
        modelMap.put("cloudVendor", cloudVendor);
        return "SSL/autoDeploy/selectKeyInfo";
    }

    /**
     * 导出云厂商key管理列表
     */
    @RequiresPermissions("SSL:cloudKeySecret:export")
    @Log(title = "云厂商key管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SslCloudKey sslCloudKey)
    {
        List<SslCloudKey> list = sslCloudKeyService.selectSslCloudKeyList(sslCloudKey);
        ExcelUtil<SslCloudKey> util = new ExcelUtil<SslCloudKey>(SslCloudKey.class);
        return util.exportExcel(list, "云厂商key管理数据");
    }

    /**
     * 新增云厂商key管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存云厂商key管理
     */
    @RequiresPermissions("SSL:cloudKeySecret:add")
    @Log(title = "云厂商key管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SslCloudKey sslCloudKey)
    {
        return toAjax(sslCloudKeyService.insertSslCloudKey(sslCloudKey));
    }

    /**
     * 修改云厂商key管理
     */
    @RequiresPermissions("SSL:cloudKeySecret:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SslCloudKey sslCloudKey = sslCloudKeyService.selectSslCloudKeyById(id);
        mmap.put("sslCloudKey", sslCloudKey);
        return prefix + "/edit";
    }

    @ResponseBody
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable("id") String id, ModelMap mmap)
    {
        return AjaxResult.success("查询成功！", sslCloudKeyService.selectSslCloudKeyById(id));
    }

    /**
     * 修改保存云厂商key管理
     */
    @RequiresPermissions("SSL:cloudKeySecret:edit")
    @Log(title = "云厂商key管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SslCloudKey sslCloudKey)
    {
        return toAjax(sslCloudKeyService.updateSslCloudKey(sslCloudKey));
    }

    /**
     * 删除云厂商key管理
     */
    @RequiresPermissions("SSL:cloudKeySecret:remove")
    @Log(title = "云厂商key管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sslCloudKeyService.deleteSslCloudKeyByIds(ids));
    }
}
